var app = getApp(),
  api = require("../../../api.js");
let handler = require("../../../utils/function.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img: handler.driverImg,
    webRoot: app.webRoot,
    page:1,
  },
  onShow:function(){
    let that = this;
    console.log('---------')
    app.request({
      url: api.bank.mybank,
      method:'post',
      data: {
        rows:10,
        page: that.data.page
      },
      success: function (e) {
        
        console.log(e)
        that.setData({
          data: e.data.data,
        })
      }
    })
  },
  onLoad: function () {
    var that = this
    that.setData({
      icons: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background',
    })
  },
  bankSetup: function (e) {
    var that = this;
    let id = e.currentTarget.dataset.id;
    // TODO 发送请求
    app.request({
      url: api.bank.is_default,
      method:'post',
      data:{
        id:id,
      },
      success:function(e){
        console.log(e)
       if(e.code==1){
         wx.showModal({
           title: '提示',
           content: '设置成功',
           showCancel: false,
           success:function(){
             that.onShow();
           }
         })
       }else{
         wx.showModal({
           title: '提示',
           content: '设置失败',
           showCancel:false
         })
       }
        
      }
    })
 
  }
  ,
  del:function(e){
    var that=this;
    var id = e.currentTarget.dataset.id;
      wx.showModal({
        title: '提示',
        content: '您确定删除吗',
        success:function(e){
          if(e.confirm==1){
            app.request({
              url: api.bank.del,
              method:'post',
              data:{
                id: id
              },
              success:function(e){
                console.log(e)
                that.onShow();
              }
            })
          }
        }
      })
  }
})